<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
		//1
		int n = 1;
		String count = (String) application.getAttribute("counter1");
		if (application.getAttribute("counter1") != null)
			n = Integer.parseInt(count);
		if (session.isNew()) 
			n++;
		String counter = String.valueOf(n);
		application.setAttribute("counter1", counter);

		//2
        if (session.getAttribute("sessionCount") == null) {
            session.setAttribute("sessionCount", new Integer(0));
        }

        Integer count2 = (Integer) session.getAttribute("sessionCount");
        session.setAttribute("sessionCount", new Integer(
                count2.intValue() + 1));
    %>
    页面计数：<%=counter%>
    <br />
    浏览器计数<%=session.getAttribute("sessionCount")%>
    <br />
</body>
</html>